package com.kaifamiao.map;

import java.util.Map;

public class MapStaticMethods {

    public static void main(String[] args) {

        Map<String,Integer> map = Map.of();
        System.out.println( map );
        System.out.println( map.getClass() );

        map = Map.of( "狄仁杰", 62, "曾泰", 40, "狄春", 28 );
        System.out.println( map );
        System.out.println( map.getClass() );

        // map.put( "李元芳", 25 ); // UnsupportedOperationException

        class Node<K,V> implements Map.Entry<K,V> {
            final K key;
            V value;
            public Node(K key,V value) {
                this.key = key;
                this.value = value;
            }
            public K getKey() {
                return key;
            }
            public V getValue() {
                return value;
            }
            public V setValue(V value) {
                V old = value;
                this.value = value;
                return old;
            }
        }

        Map.Entry<String,Integer> e1 = new Node<>( "李元芳", 25 );
        Map.Entry<String,Integer> e2 = new Node<>( "李某芳", 18 );
        Map.Entry<String,Integer> e3 = new Node<>( "单田芳", 19 );

        map = Map.ofEntries( e1, e2, e3 );
        System.out.println( map );
        System.out.println( map.getClass() );

    }

}
